﻿using System;

namespace Jodell.Transport.Ethercat
{
    /** Possible error codes returned. */
    public enum ec_err : UInt16
    {
        /** No error */
        EC_ERR_OK = 0,
        /** Library already initialized. */
        EC_ERR_ALREADY_INITIALIZED,
        /** Library not initialized. */
        EC_ERR_NOT_INITIALIZED,
        /** Timeout occurred during execution of the function. */
        EC_ERR_TIMEOUT,
        /** No slaves were found. */
        EC_ERR_NO_SLAVES,
        /** Function failed. */
        EC_ERR_NOK
    }


    /** Possible EtherCAT slave states */
    public enum ec_state : UInt16
    {
        /** No valid state. */
        EC_STATE_NONE = 0x00,
        /** Init state*/
        EC_STATE_INIT = 0x01,
        /** Pre-operational. */
        EC_STATE_PRE_OP = 0x02,
        /** Boot state*/
        EC_STATE_BOOT = 0x03,
        /** Safe-operational. */
        EC_STATE_SAFE_OP = 0x04,
        /** Operational */
        EC_STATE_OPERATIONAL = 0x08,
        /** Error or ACK error */
        EC_STATE_ACK = 0x10,
        EC_STATE_ERROR = 0x10
    }


    /** Possible buffer states */
    public enum ec_bufstate : UInt16
    {
        /** Empty */
        EC_BUF_EMPTY = 0x00,
        /** Allocated, but not filled */
        EC_BUF_ALLOC = 0x01,
        /** Transmitted */
        EC_BUF_TX = 0x02,
        /** Received, but not consumed */
        EC_BUF_RCVD = 0x03,
        /** Cycle completed */
        EC_BUF_COMPLETE = 0x04
    }


    /** Ethercat data types */
    public enum ec_datatype : UInt16
    {
        ECT_BOOLEAN = 0x0001,
        ECT_INTEGER8 = 0x0002,
        ECT_INTEGER16 = 0x0003,
        ECT_INTEGER32 = 0x0004,
        ECT_UNSIGNED8 = 0x0005,
        ECT_UNSIGNED16 = 0x0006,
        ECT_UNSIGNED32 = 0x0007,
        ECT_REAL32 = 0x0008,
        ECT_VISIBLE_STRING = 0x0009,
        ECT_OCTET_STRING = 0x000A,
        ECT_UNICODE_STRING = 0x000B,
        ECT_TIME_OF_DAY = 0x000C,
        ECT_TIME_DIFFERENCE = 0x000D,
        ECT_DOMAIN = 0x000F,
        ECT_INTEGER24 = 0x0010,
        ECT_REAL64 = 0x0011,
        ECT_INTEGER64 = 0x0015,
        ECT_UNSIGNED24 = 0x0016,
        ECT_UNSIGNED64 = 0x001B,
        ECT_BIT1 = 0x0030,
        ECT_BIT2 = 0x0031,
        ECT_BIT3 = 0x0032,
        ECT_BIT4 = 0x0033,
        ECT_BIT5 = 0x0034,
        ECT_BIT6 = 0x0035,
        ECT_BIT7 = 0x0036,
        ECT_BIT8 = 0x0037
    }


    /** Ethercat command types */
    public enum ec_cmdtype : UInt16
    {
        /** No operation */
        EC_CMD_NOP = 0x00,
        /** Auto Increment Read */
        EC_CMD_APRD,
        /** Auto Increment Write */
        EC_CMD_APWR,
        /** Auto Increment Read Write */
        EC_CMD_APRW,
        /** Configured Address Read */
        EC_CMD_FPRD,
        /** Configured Address Write */
        EC_CMD_FPWR,
        /** Configured Address Read Write */
        EC_CMD_FPRW,
        /** Broadcast Read */
        EC_CMD_BRD,
        /** Broadcast Write */
        EC_CMD_BWR,
        /** Broadcast Read Write */
        EC_CMD_BRW,
        /** Logical Memory Read */
        EC_CMD_LRD,
        /** Logical Memory Write */
        EC_CMD_LWR,
        /** Logical Memory Read Write */
        EC_CMD_LRW,
        /** Auto Increment Read Multiple Write */
        EC_CMD_ARMW,
        /** Configured Read Multiple Write */
        EC_CMD_FRMW
        /** Reserved */
    }

    /** Ethercat EEprom command types */
    public enum ec_ecmdtype : UInt16
    {
        /** No operation */
        EC_ECMD_NOP = 0x0000,
        /** Read */
        EC_ECMD_READ = 0x0100,
        /** Write */
        EC_ECMD_WRITE = 0x0201,
        /** Reload */
        EC_ECMD_RELOAD = 0x0300
    }
}
